<?php

/*
 * $Id: $
 * $Author: $
 * $LastChangedDate: $
 * $Revision: $
 */

namespace cmFly\controller\request;

class http_rewrite extends base {

    private $uri;
    private $file;

    public function get_content_encoding() {
	return 'utf-8';
    }

    public function get_request_type() {
	return 'http';
    }

    public function get_user_info() {
	return Array(
	    'ip' => $_SERVER['REMOTE_ADDR'],
	    'user_agent' => @$_SERVER['HTTP_USER_AGENT'],
	    'accept_language' => @$_SERVER['HTTP_ACCEPT_LANGUAGE']
	);
    }

    public function get_file() {
	if (!isset($this->file)) {
	    $this->file = $_SERVER['DOCUMENT_ROOT'] . $this->get_uri();
	}
	return $this->file;
    }

    protected function get_uri() {
	if (!isset($this->uri)) {
	    $req_uri = preg_replace("#^(.*?)\?.*$#", "$1", $_SERVER['REQUEST_URI']);
	    $req_uri = str_replace(Array("%60", "+"), Array("'", " "), rawurldecode($req_uri));
	    $this->uri = $req_uri;
	}
	return $this->uri;
    }

    public function get_route() {
	$uri = substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT']));
	$uri = str_replace('\\', '/', $uri);
	$req_uri = $this->get_uri();
	$cmd = '';
	if ($uri != $req_uri) {
	    $cmd = substr($req_uri, strlen(dirname($uri)) + 1);
	    if ($cmd[strlen($cmd) - 1] == '/') {
		$cmd = substr($cmd, 0, -1);
	    }
	}

	if (empty($cmd)) {
	    return FALSE;
	}
	return $cmd;
    }

    public function get_args() {
	
    }

}